home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / rcs / cnumber.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.8 KB  |  336 lines

  1. head    1.3;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.3; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.3
  10. date    97.07.14.04.19.43;    author dlorre;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    96.08.28.19.55.41;    author dlorre;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    96.08.22.02.05.10;    author dlorre;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @Oui.lib -- Object User Interface
  27. Projet créé en 1994
  28. Auteur: Dominique Lorre
  29. @
  30.  
  31.  
  32. 1.3
  33. log
  34. @*** empty log message ***
  35. @
  36. text
  37. @//$Id: cnumber.cc 1.2 1996/08/28 19:55:41 dlorre Exp dlorre $
  38. #include <graphics/gfxmacros.h>
  39. #include <intuition/intuition.h>
  40. #include <intuition/classes.h>
  41. #include <intuition/classusr.h>
  42. #include <intuition/imageclass.h>
  43. #include <intuition/gadgetclass.h>
  44. #include <intuition/icclass.h>
  45. #include <intuition/cghooks.h>
  46. #include <libraries/gadtools.h>
  47.  
  48. #include <string.h>
  49. #include <stdio.h>
  50. #include <mydebug.h>
  51.  
  52. #include "screen.h"
  53. #include "window.h"
  54. #include "gadgets/cnumber.h"
  55. #include "gadgets/eclass.h"
  56. #include "gadgetlist.h"
  57.  
  58. #include <proto/exec.h>
  59. #include <proto/graphics.h>
  60. #include <proto/intuition.h>
  61. #include <proto/utility.h>
  62. #include <clib/alib_protos.h>
  63.  
  64. IMPORT Class *BOOPSIELabel ;
  65. IMPORT int InitELabel(void) ;
  66. IMPORT void FreeELabel(void) ;
  67.  
  68.  
  69. // ========================================================================
  70. // ==========================  CNUMBER CLASS ==============================
  71. // ========================================================================
  72. cnumber::cnumber(gadgetlist *gl,
  73.                  void (window::*func)(gadget *, unsigned long, unsigned short),
  74.                  const char *t,
  75.                  long val,
  76.                  long border, long place, char style) : gadget(gl, func)
  77. {
  78. int i, l1, l2 ;
  79. BOOL underset = FALSE ;
  80. UWORD *pens = gl->win->ws->drawinfo->dri_Pens;
  81. short gleft, gtop, gwidth, gheight ;
  82.  
  83.     gl->ng->ng_Flags = place ;
  84.     InitELabel() ;
  85.  
  86.     gleft = gl->ng->ng_LeftEdge ;
  87.     gtop = gl->ng->ng_TopEdge ;
  88.     gwidth = gl->ng->ng_Width ;
  89.     gheight = gl->ng->ng_Height ;
  90.  
  91.     if (style & BOTTOMCNUMBER)
  92.         gtop = short(-gtop) ;
  93.     if (style & RIGHTCNUMBER)
  94.         gleft = short(-gleft) ;
  95.     if (style & WIDTHCNUMBER)
  96.         gwidth = short(-gwidth) ;
  97.     if (style & HEIGHTCNUMBER)
  98.         gheight = short(-gheight) ;
  99.  
  100.  
  101.     if (t) {
  102.  
  103.         it1 = new IntuiText ;
  104.         it2 = new IntuiText ;
  105.         it3 = new IntuiText ;
  106.  
  107.         plain = new TTextAttr ;
  108.         underline = new TTextAttr ;
  109.  
  110.         it1->FrontPen = it2->FrontPen = it3->FrontPen = gl->win->ws->drawinfo->dri_Pens[(place&NG_HIGHLABEL)?HIGHLIGHTTEXTPEN:TEXTPEN] ;
  111.         it1->BackPen = it2->BackPen = it3->BackPen = 0 ;
  112.         it1->DrawMode = it2->DrawMode = it3->DrawMode = JAM1 ;
  113.  
  114.         norm1 = new char[strlen(t)+1] ;
  115.         norm2 = new char[strlen(t)+1] ;
  116.         under = new char[2] ;
  117.  
  118.         underkey(t) ;
  119.  
  120.         CopyMem(gl->win->ws->scr->Font, plain, sizeof(struct TTextAttr)) ;
  121.         CopyMem(gl->win->ws->scr->Font, underline, sizeof(struct TTextAttr)) ;
  122.         underline->tta_Style |= FSF_UNDERLINED ;
  123.         font = OpenFont((TextAttr *)underline) ;
  124.  
  125.         for (i=l1=l2=0; t[i]; i++) {
  126.             if (t[i] == '_') {
  127.                 if (t[i+1]) under[0] = t[++i] ;
  128.                 underset = TRUE ;
  129.             }
  130.             else {
  131.                 if (underset) {
  132.                     norm2[l2++] = t[i] ;
  133.                 }
  134.                 else {
  135.                     norm1[l1++] = t[i] ;
  136.                 }
  137.             }
  138.         }
  139.         norm1[l1] = '\0' ;
  140.         norm2[l2] = '\0' ;
  141.         under[1] = '\0' ;
  142.  
  143.         if (l1) {
  144.             it1->IText = (UBYTE *)norm1 ;
  145.             it1->ITextFont = (TextAttr *)plain ;
  146.             if (underset) {
  147.                 it1->NextText = it2 ;
  148.                 it2->LeftEdge = short(IntuiTextLength(it1)) ;
  149.                 it2->IText = (UBYTE *)under ;
  150.                 it2->ITextFont = (TextAttr *)underline ;
  151.                 if (l2) {
  152.                     it2->NextText = it3 ;
  153.                     it3->LeftEdge = short(it2->LeftEdge + IntuiTextLength(it2)) ;
  154.                     it3->IText = (UBYTE *)norm2 ;
  155.                     it3->ITextFont = (TextAttr *)plain ;
  156.                 }
  157.             }
  158.         }
  159.         else if (underset) {
  160.             it1->IText = (UBYTE *)under ;
  161.             it1->ITextFont = (TextAttr *)underline ;
  162.             it1->NextText = it2 ;
  163.             it2->LeftEdge = short(IntuiTextLength(it1)) ;
  164.             it2->IText = (UBYTE *)norm2 ;
  165.             it2->ITextFont = (TextAttr *)plain ;
  166.         }
  167.     }
  168.     gad = gl->gad = (Gadget *)NewObject(BOOPSIELabel, NULL,
  169.             GA_ID,          id,
  170.             GA_Top,         gtop,
  171.             GA_Left,        gleft,
  172.             GA_Width,       gwidth,
  173.             GA_Height,      gheight,
  174.  
  175.             (style & BOTTOMCNUMBER)?GA_RelBottom:TAG_IGNORE,   TRUE,
  176.             (style & RIGHTCNUMBER)?GA_RelRight:TAG_IGNORE,     TRUE,
  177.             (style & WIDTHCNUMBER)?GA_RelWidth:TAG_IGNORE,     TRUE,
  178.             (style & HEIGHTCNUMBER)?GA_RelHeight:TAG_IGNORE,   TRUE,
  179.  
  180.  
  181.             GA_Previous,    gl->gad,
  182.             GA_IntuiText,   it1 ,
  183.             GA_Border,      border,
  184.             GA_Text,        val,
  185.             EGA_Flags,      place,
  186.             EGA_TextAttr,   gl->ng->ng_TextAttr,
  187.             EGA_XPens,      gl->win->ws->xpens,
  188.             EGA_GPen,       gl->gpen,
  189.             EGA_Number,     val,
  190.  
  191.             TAG_END) ;
  192. }
  193.  
  194. cnumber::~cnumber()
  195. {
  196.     if (norm1) delete norm1 ;
  197.     if (norm2) delete norm2 ;
  198.     if (under) delete under ;
  199.  
  200.     if (it1) delete it1 ;
  201.     if (it2) delete it2 ;
  202.     if (it3) delete it3 ;
  203.  
  204.     if (plain) delete plain ;
  205.     if (underline) delete underline ;
  206.  
  207.     if (gad) DisposeObject(gad) ;
  208.     if (font) CloseFont(font) ;
  209.     FreeELabel() ;
  210. }
  211.  
  212. void cnumber::set(LONG val)
  213. {
  214.     SetGadgetAttrs((Gadget *)gad, w, NULL,
  215.         EGA_Number,    val,
  216.         TAG_END) ;
  217. }
  218.  
  219. void cnumber::keystroke(BOOL shifted)
  220. {
  221.     if (gfunc)
  222.         gadget::action(NULL, 0) ;
  223.     else
  224.         glist->selectgadget(id+1, shifted) ;
  225. }
  226.  
  227.  
  228. @
  229.  
  230.  
  231. 1.2
  232. log
  233. @passage en gadget BOOPSI (via cstring)
  234. @
  235. text
  236. @d1 1
  237. a1 1
  238. //$Id$
  239. d14 1
  240. d22 5
  241. a26 19
  242. #include <cxxproto/graphics.h>
  243. #include <cxxproto/intuition.h>
  244. #include <cclib/alib_protos.h>
  245.  
  246. extern "C" {
  247.  
  248. extern struct ExecBase *SysBase ;
  249. void CopyMem( APTR source, APTR dest, unsigned long size );
  250. #pragma libcall SysBase CopyMem 270 09803
  251.  
  252. extern struct Library *UtilityBase ;
  253. struct TagItem *FindTagItem( Tag tagVal, struct TagItem *tagList );
  254. ULONG GetTagData( Tag tagValue, unsigned long defaultVal,
  255.         struct TagItem *tagList );
  256. #include <pragmas/utility_pragmas.h>
  257.  
  258. void kprintf(STRPTR format, ...) ;
  259. }
  260.  
  261. d38 1
  262. a38 1
  263.                  STRPTR t,
  264. d84 2
  265. a85 2
  266.         CopyMem(gl->win->ws->screen->Font, plain, sizeof(struct TTextAttr)) ;
  267.         CopyMem(gl->win->ws->screen->Font, underline, sizeof(struct TTextAttr)) ;
  268. d108 1
  269. a108 1
  270.             it1->IText = norm1 ;
  271. d113 1
  272. a113 1
  273.                 it2->IText = under ;
  274. d118 1
  275. a118 1
  276.                     it3->IText = norm2 ;
  277. d124 1
  278. a124 1
  279.             it1->IText = under ;
  280. d128 1
  281. a128 1
  282.             it2->IText = norm2 ;
  283. @
  284.  
  285.  
  286. 1.1
  287. log
  288. @Initial revision
  289. @
  290. text
  291. @d1 9
  292. d12 5
  293. d18 1
  294. d21 4
  295. d26 12
  296. a37 6
  297. extern struct Library *GadToolsBase ;
  298. struct Gadget *CreateGadget( unsigned long kind, struct Gadget *gad,
  299.         struct NewGadget *ng, Tag tag1, ... );
  300. void GT_SetGadgetAttrs( struct Gadget *gad, struct Window *win,
  301.         struct Requester *req, Tag tag1, ... );
  302. #include <pragmas/gadtools_pragmas.h>
  303. d41 5
  304. a48 1
  305.  
  306. d51 1
  307. a51 1
  308.                  STRPTR titre,
  309. d53 1
  310. a53 1
  311.                  long border, long place) : gadget(gl, func)
  312. d55 5
  313. a59 1
  314.     gl->ng->ng_GadgetText = titre ;
  315. d61 107
  316. a167 4
  317.     gad = gl->gad = CreateGadget(NUMBER_KIND, gl->gad, gl->ng,
  318.             GTNM_Number, val,
  319.             GTNM_Border, border,
  320.             GT_Underscore,  '_',
  321. d173 14
  322. d189 1
  323. a189 1
  324. void cnumber::set(long val)
  325. d191 3
  326. a193 3
  327.     GT_SetGadgetAttrs(gad, w, NULL,
  328.         GTNM_Number, val,
  329.         TAG_DONE) ;
  330. a195 1
  331.  
  332. d198 7
  333. a204 2
  334.     glist->selectgadget(id+1, shifted) ;
  335. }@
  336.